﻿using System;
using System.Collections.Generic;
using System.Data;
using UniversityStudentManagemnetSystem.DAO.DAL;
using UniversityStudentManagemnetSystem.DAO.Gateway;

namespace UniversityStudentManagemnetSystem.BLL
{
    public class EmployeeManager
    {
        EmployeeGateway employeeGateway =new EmployeeGateway();
        public bool SaveEmployee(Employee aEmployee)
        {
            if (employeeGateway.HasThisEmail(aEmployee.Email))
            {
                throw new Exception("This Email " + " " + aEmployee.Email + " " + " already exist! Please try again");
            }
            else if (employeeGateway.HasThisNationalIdNumber(aEmployee.NationalIdNumber))
            {
                throw new Exception("This National Id " + " " + aEmployee.NationalIdNumber + " " + "already exist! Please try again.");
            }
            else
            {
                return employeeGateway.SaveEmployee(aEmployee);
            }
        }
       public int GetPreviousEmployeeId()
        {
            return employeeGateway.GetPreviousEmployeeId();
        }

       //public DataTable GetAllEmployeeDesignation(int selectedDesignation)
       //{
       //    return employeeGateway.GetAllEmployeeFor(selectedDesignation);

       //}

        //public DataTable GetAllEmployee()
        //{
        //  return  employeeGateway.GetAllEmployee();
        //}

        public Employee GetEmployeeFor(string searchText)
        {
            if (searchText != "")
            {
                return employeeGateway.GetEmployeeFor(searchText);
            }
            else
            {
                throw new Exception("Please fill The Search Field Properly");
            }
        }

        public List<Employee> GetEmployeeForSelectItem(int selectedDesignation)
        {
            return employeeGateway.GetAllEmployeeForSelectItem(selectedDesignation);
        }


        public List<Employee> GetAllEmployeeList()
        {
            return employeeGateway.GetEmployeelist();
        }
        //For edit Employee
        internal Employee GetEmployeeById(int id)
        {
            return employeeGateway.GetAllEmployeeFors(id);
        }


        public bool UpdateEmployeeInformation(Employee aEmployee)
        {
            if (aEmployee.Name == "" && aEmployee.ContactNumber == "" && aEmployee.Email == "")
            {
                throw new Exception("Please Fill Up All Field Properly!");
            }
            else
            {
                return employeeGateway.UpdateEmployeeInformation(aEmployee);
            }
        }
    }
}